import Tab from '../tab/tab.vue'
import Detail from '../audit-detail/audit-detail.vue'
import Pages from '../../../pages/pages.vue'
import { showMsg, setMenuType, getPromoterAuditList } from '../../../../vuex/action'

export default {
  name: 'promoter-list',
  components: {
    'vue-tab': Tab,
    'vue-detail': Detail,
    'vue-pages': Pages
  },
  data() {
    return {
      list: [],
      pages: {
        start: 0,
        totalPages: 0,
        limit: 20
      },
      detailId: '',
      showModal: false
    }
  },
  vuex: {
    getters: {
      fresh: state => state.promoterAuditListNeedFresh
    },
    actions: {
      xShowMsg: showMsg,
      xSetMenuType: setMenuType,
      xGetList: getPromoterAuditList
    }
  },
  ready() {
    this.xSetMenuType('activity')
    this.getList({})
  },
  methods: {
    getList({start=this.pages.start, limit=this.pages.limit}) {
      this.xGetList({
        start: start,
        limit: limit
      })
        .then((data) => {
          this.list = data.list
          this.pages.totalPages = Math.ceil(data.totalCount / limit)
        })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    },
    showDetail(id) {
      this.detailId = id
      this.showModal = true
    }
  },
  watch: {
    fresh() {
      if (this.fresh) {
        this.getList({})
      }
    }
  }
}
